<?php

namespace App\Jobs;

use App\Http\Service\DeviceService;
use App\Model\Device;
use App\Model\DeviceBus;
use App\Model\DeviceBuslog;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Storage;


class CheckReduce implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    private $logId;
    public $tries = 1;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function  __construct($logId)
    {

        $this->logId = $logId;
        //因为要导入大文件 需要很久时间
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
       $log = DeviceBuslog::query()->where('id',$this->logId)->first();
       $device =  Device::query()->where('id',$log->mem_device_id)->first();
       if(empty($device)){
           $log->status = 3;
           $log->after_du =$device->du;
           $log->save();
           return '';
       }
       Log::info('device->du:'.$device.'----'.'log->du'.$log->du.'-----'.'log->mem_du'.$log->mem_du);
       if($device->du+$log->du <= $log->mem_du+0.01){
            $log->after_du = $device->du;
            $log->status =1;
            $log->save();
       }else{
           $log->after_du =$device->du;
           $log->status = 3;
           $log->save();
       }
    }
}

